<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/public/common.jspf" %>

<head>
    <title>用户添加</title>
    <!--validateion-->
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/scripts/jquery_validate/jquery.validate.min.js"></script>
    <script type="text/javascript">
        //validate
        $(document).ready(function () {
            $('form').validate({
                rules: {
                    loginName: {
                        required: true,
                        minlength: 6,
                        maxlength: 255
                    },
                    name: {
                        required: true,
                        maxlength: 255
                    },
                    department: {
                        required: true,
                        maxlength: 255
                    },
                    email: {
                        required: true,
                        maxlength: 255,
                        email: true
                    },
                    roleId: {
                        required: true
                    }
                },
                messages: {
                    loginName: {
                        required: '请输入登录名',
                        minlength: '登录名长度在6-255字符之间',
                        maxlength: '登录名长度在6-255字符之间'
                    },
                    name: {
                        required: '请输入姓名',
                        maxlength: '姓名长度不超过255字符'
                    },
                    department: {
                        required: '请输入部门',
                        maxlength: '部门长度不超过255字符'
                    },
                    email: {
                        required: '请输入邮箱',
                        maxlength: '邮箱长度不超过255字符',
                        email: '不符合邮箱格式'
                    },
                    roleId: {
                        required: '请选择角色'
                    }
                }
            });
        });
    </script>
</head>

<div class="col-sm-9">
    <div class="row">
        <div class="col-lg-12">
            <div class="page-header">
                <h1>用户管理</h1>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <%@ include file="/WEB-INF/jsp/public/pageinfo.jspf" %>
            <div class="panel panel-default bootstrap-admin-no-table-panel">
                <div class="panel-heading">
                    <div class="text-muted bootstrap-admin-box-title">添加新用户</div>
                </div>
                <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                    <s:form cssClass="form-horizontal" action="userManage_%{id==null?'add':'edit'}">
                        <fieldset>
                            <legend>用户信息</legend>
                            <s:hidden name="id"></s:hidden>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">登录名</label>

                                <div class="col-lg-10">
                                    <s:if test="id==null">
                                        <s:textfield class="form-control" name="loginName" cssClass="form-control"/>
                                        <s:fielderror fieldName="loginName"/>
                                    </s:if>
                                    <s:else>
                                        ${loginName}
                                    </s:else>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">角色分配</label>

                                <div class="col-lg-10">
                                    <s:select cssClass="form-control" list="#roleList" listKey="id" listValue="name"
                                              headerValue="请分配用户角色" name="roleId"/>
                                    <s:fielderror fieldName="roleId"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">姓名</label>

                                <div class="col-lg-10">
                                    <s:textfield cssclass="form-control" name="name" cssClass="form-control"/>
                                    <s:fielderror fieldName="name"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">所在部门</label>

                                <div class="col-lg-10">
                                    <s:textfield cssclass="form-control" name="department" cssClass="form-control"/>
                                    <s:fielderror fieldName="department"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">邮箱</label>

                                <div class="col-lg-10">
                                    <s:textfield cssclass="form-control" name="email" cssClass="form-control"/>
                                    <s:fielderror fieldName="email"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-lg-10 col-lg-offset-2">
                                    <p class="help-block">密码默认为123456</p>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-10 col-lg-offset-2">
                                    <button type="submit" class="btn btn-primary">保存</button>
                                    <s:a cssClass="btn btn-default" action="userManage_list">取消并返回列表</s:a>
                                </div>
                            </div>
                        </fieldset>
                    </s:form>
                </div>
            </div>
        </div>
    </div>
</div>